#coding:utf-8

import json

from cos import cos
from cos import scut,tcut,get_sim,get_sim_score

from get_score import get_score

# 对旧版
def test_case1(location1,location2):
    f1 = open(location1,mode='r')
    f2 = open(location2,mode='w')

    for line in f1:
        n = json.loads(line)

        v1 = n['v1']
        v2 = n['v2']
        sim = get_sim_score(v1,v2)

        res = [n['z'],n['i1'],n['t1'],n['i2'],n['t2'],sim]
        line = json.dumps(res,ensure_ascii=False)
        f2.write(line.encode('utf-8')+'\n')

    f1.close()
    f2.close()

# 对新版
def test_case2(location1,location2,scorer='1'):
    f1 = open(location1,mode='r')
    f2 = open(location2,mode='w')

    for line in f1:
        n = json.loads(line)

        v1 = get_score(n['ct1'],n['cc1'],scorer)
        v2 = get_score(n['ct2'],n['cc2'],scorer)

        sim = get_sim_score(v1,v2)

        res = [n['z'],n['i1'],n['t1'],n['i2'],n['t2'],sim]
        line = json.dumps(res,ensure_ascii=False)
        f2.write(line.encode('utf-8')+'\n')

    f1.close()
    f2.close()

if __name__ == '__main__':

    print 'Experiment'

    location = 'data/issue.v.txt'

    location0 = 'data/issue.sim0.txt'
    location1 = 'data/issue.sim1.txt'
    location2 = 'data/issue.sim2.txt'
    location3 = 'data/issue.sim3.txt'
    location4 = 'data/issue.sim4.txt'
    location5 = 'data/issue.sim5.txt'
    location6 = 'data/issue.sim6.txt'
    location7 = 'data/issue.sim7.txt'
    location8 = 'data/issue.sim8.txt'
    location8 = 'data/issue.sim9.txt'

    test_case1(location,location0)
    test_case2(location,location1,scorer="1")
    test_case2(location,location2,scorer="2")
    test_case2(location,location3,scorer="3")
    test_case2(location,location4,scorer="4")
    test_case2(location,location5,scorer="5")
    test_case2(location,location6,scorer="6")
    test_case2(location,location7,scorer="7")
    test_case2(location,location8,scorer="8")
    test_case2(location,location8,scorer="9")

